package com.example.backend.controller;

import com.example.backend.entity.Dishes;
import com.example.backend.entity.Shop;
import com.example.backend.service.DishesService;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.ArrayList;

@RestController
@CrossOrigin
public class DishesController {
    @Autowired
    private DishesService dishesService;
    
    @PostMapping("/dishes")
    public int doAdd(@RequestBody Dishes dishes){
        return dishesService.addDishes(dishes);
    }

    @PutMapping("/dishes")
    public int doUpdate(@RequestBody Dishes dishes){
        return dishesService.updateDishes(dishes);
    }

    @DeleteMapping("/dishes/{id}")
    public int doDelete(@PathVariable("id") Integer id){
        return dishesService.deleteDishesById(id);
    }

    @GetMapping("/dishes/{id}")
    public Dishes doGet(@PathVariable("id") Integer id){
        return dishesService.selectDishesById(id);
    }

    @GetMapping("/dishes")
    public ArrayList<Dishes> doList(Dishes dishes){
        return dishesService.selectDishes(dishes);
    }


    @GetMapping("/dishes/shop")
    public ArrayList<Dishes> doListByShopId(String id){
        System.out.println(id);
        return dishesService.selectDishesByShopId(id);
    }
    @GetMapping("/dishesGetPage")
    public PageInfo<Dishes> shopGetPage(
            @RequestParam(defaultValue = "1") Integer pageNum,
            @RequestParam(defaultValue = "5") Integer pageSize,
            Dishes  dishes) {  // ✅ 接收查询条件
        return dishesService.dishesGetPage(pageNum, pageSize, dishes);
    }
}